<?php

class Core_Backend_Component_Permission_View_Account_Create extends Core_Backend_Share_View_Form {

    protected function buildToolbar($toolbar) {
    	$group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('permission/account/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.save'))
        	  ->bindEvent('click', "Kdf.Ui.getForm('".$this->getForm()->getId()."').submit('".$this->getUrl(NULL, 'save')."')");
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form) {
        $entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())->setId('account_form')->addHiddenField('id', 'account[id]');
        $form->addTextboxField($this->__('share.label.userName'), 'user_name', 'account[user_name]', TRUE)
                ->addMultiRule('required', 'character');
        $form->addTextboxField($this->__('permission.label.full_name'), 'full_name', 'account[full_name]');
        $form->addPasswordField($this->__('share.label.password'), 'password', "account[password]", TRUE)
                ->addRequiredRule();
        $form->addPasswordField($this->__('share.label.repassword'), 'repassword', "account[repassword]", TRUE)
                ->addRequiredRule();
        $form->addTextboxField($this->__('permission.label.email'), 'email', 'account[email]')
                ->addMultiRule('email');
        $form->addSelectField($this->__('permission.label.accountGrade'), 'grade', 'account[grade]', TRUE)
                ->addRequiredRule()
                ->setOption($this->__('permission.label.normalAccount'), 'na')
                ->setOption($this->__('permission.label.superAdmin'), 'sa');
        $form->addSelectField($this->__('permission.label.isavailable'), 'status', 'account[status]')
                ->setOption($this->__('status.boolean.1'),'enabled')
                ->setOption($this->__('status.boolean.0'),'disabled');
        $form->addSelectField($this->__('permission.label.backend_access'), 'is_backend', 'account[is_backend]')
                ->setOption($this->__('status.boolean.1'),'1')
                ->setOption($this->__('status.boolean.0'),'4');
        $form->addComboTreeField($this->__('permission.label.role'), 'role_ids', 'account[role_ids][]')
        		->setDefaultOption('', '--')
                ->bindData($this->getRoles()->toArray(), 0, array('valueKey' => 'id', 'textKey' => 'name', 'parentKey' => 'parent_id', 'childKey' => 'id'))
                ->setMultiple(TRUE)
                ->setSize(10);
        
        if (!is_null($entity)) {
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }

}